<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<%
			response.addHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
		%>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>系统</title>
		<link href="css/sys.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" type="text/css"
			href="jeasyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="jeasyui/themes/icon.css">
		<script src="js/jquery.js"></script>
		<script type="text/javascript" src="jeasyui/jquery.easyui.min.js"></script>
		<script type="text/javascript"
			src="jeasyui/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
		<style type="text/css">
			.showworklog{
				width: 100%;
				height: 150px;
			}
		</style>
		<script type="text/javascript">
	$(function() {
		$("#seachstartdate").attr("value", nowDate());
		$("#seachenddate").attr("value", nowDate());
		WdatePicker({
			isShowWeek : true,
			eCont : "div1",
			onpicked : function(dp) {
				$("#showmydaylog").empty();
				var url="daylog.do?method=getNowDateDayLogList&nowdate="
					+ dp.cal.getDateStr()+"&nowtime="+new Date();
				showdaylog(url);
			}
		});
	});
	function searchworklog(){
		if($("#seachstartdate").val()==""){
			$.messager.alert("提示","开始日期不能为空~~","info");
			return;
		}else if($("#seachenddate").val()==""){
			$.messager.alert("提示","结束日期不能为空~~","info");
			return;
		}else if($("#seachstartdate").val()>$("#seachenddate").val()){
			$.messager.alert("提示","开始日期不能晚于结束日期~~","info");
			return;
		}
		var url = "daylog.do?method=searchDayLogList&startdate="
			+ $("#seachstartdate").val()+"&enddate="+$("#seachenddate").val()+"&nowtime="+new Date();
		$("#showmydaylog").empty();
		showdaylog(url);
	}
	//添加模块
	function addmydaylog() {
		$("#workdate").attr("value", nowDate());
		$("#addmyworklog").show();
		$("#addmyworklog").dialog({
			title : "添加日志",
			modal : true,
			width : 480,
			height : 520,
			collapsible : true,
			minimizable : false,
			maximizable : false,
			buttons : [ {
				text : "提交",
				iconCls : "icon-ok",
				handler :function(){tijiao();}
			},{
				text : "保存",
				iconCls : "icon-ok",
				handler :function(){ baocun();}
			},{
				text : "取消",
				iconCls : "icon-undo",
				handler : function(){quxiao();}
			}]
		});
	}

	function baocun() {
		$("#iscommit").attr("value", "0");
		$("#myworkform").form("submit", {
			url : "daylog.do?method=addDayLog&nowtime="+new Date(),
			onSubmit : function() {
				var flag = true;
				if ($("#workdate").val() == "") {
					$.messager.alert("警告信息", "选择日志日期~~", "warning");
					flag = false;
				} else if ($("#workcontent").val() == "") {
					$.messager.alert("警告信息", "输入日志内容~~", "warning");
					flag = false;
				}
				return flag;
			},
			success : function(data) {
				$("#addmyworklog").dialog("close");
				showmsg(data);
			}
		});
		$("#showmydaylog").empty();
		var url="daylog.do?method=getNowDateDayLogList&nowdate="
			+ $("#workdate").val()+"&nowtime="+new Date();
		showdaylog(url);
	}
	function gengxin() {
		$("#myworkform").form("submit", {
			url : "daylog.do?method=updateDayLog&nowtime="+new Date(),
			onSubmit : function() {
				var flag = true;
				if ($("#workdate").val() == "") {
					$.messager.alert("警告信息", "选择日志日期~~", "warning");
					flag = false;
				} else if ($("#workcontent").val() == "") {
					$.messager.alert("警告信息", "输入日志内容~~", "warning");
					flag = false;
				}
				return flag;
			},
			success : function(data) {
				$("#addmyworklog").dialog("close");
				showmsg(data);
			}
		});
		searchworklog();
	}
	function tijiao() {
		$("#iscommit").attr("value", "1");
		$("#myworkform").form("submit", {
			url : "daylog.do?method=addDayLog&nowtime="+new Date(),
			onSubmit : function() {
				var flag = true;
				if ($("#workdate").val() == "") {
					$.messager.alert("警告信息", "选择日志日期~~", "warning");
					flag = false;
				} else if ($("#workcontent").val() == "") {
					$.messager.alert("警告信息", "输入日志内容~~", "warning");
					flag = false;
				}
				return flag;
			},
			success : function(data) {
				$("#addmyworklog").dialog("close");
				showmsg(data);
			}
		});
		$("#showmydaylog").empty();
		var url="daylog.do?method=getNowDateDayLogList&nowdate="
			+ $("#workdate").val()+"&nowtime="+new Date();
		showdaylog(url);
	}
	function updatedaylog(daylogid){
		$.ajax({
			type : "POST",
			dataType : "json",
			url : "daylog.do?method=getDayLogById&nowtime=" + new Date(),
			data : {
				"id" : daylogid
			},
			success : function(data) {
				$("#id").attr("value", data.id);
				$("#workdate").attr("value", data.workdate);
				$("#workaddress").attr("value", data.workaddress);
				$("#starttime").attr("value", data.starttime);
				$("#endtime").attr("value", data.endtime);
				$("#workcontent").attr("value", data.workcontent);
				$("#iscommit").attr("value", data.iscommit);
				$("#userid").attr("value", data.userid);
			}
		});
		$("#addmyworklog").show();
		$("#addmyworklog").dialog({
			title : "更新日志",
			modal : true,
			width : 480,
			height : 520,
			collapsible : true,
			minimizable : false,
			maximizable : false,
			buttons : [{
				text : "更新",
				iconCls : "icon-ok",
				handler :function(){ gengxin();}
			},{
				text : "取消",
				iconCls : "icon-undo",
				handler : function(){quxiao();}
			}]
		});
	}
	function commitdaylog(daylogid){
		$.ajax({
			type : "POST",
			dataType : "text",
			url : "daylog.do?method=commitDayLog&iscommit=1&nowdate=" + new Date(),
			data : {
				"id" : daylogid
			},
			success : function(data) {
				showmsg(data);
			}
		});
		searchworklog();
	}
	function quxiao() {
		$("#addmyworklog").dialog("close");
	}

	function showdaylog(url) {
		$
				.ajax({
					type : "get",
					dataType : "json",
					url : url,
					success : function(data) {
						$
								.each(
										data,
										function(index, worklog) {
											var commitflag="已经提交~~";
											if(worklog.iscommit==0){
												commitflag="<a href='javascript:void(0)' onclick=\"updatedaylog('"+worklog.id+"')\">修改</a>|<a href='javascript:void(0)' onclick=\"commitdaylog('"+worklog.id+"')\">提交</a>";
											}
											var worktimes= parseFloat(worklog.endtime)-parseFloat(worklog.starttime);
											$("#showmydaylog")
													.append(
															"<div id='"+worklog.id+"' class='icon-worklog'>"
																	+ worklog.workdate+"["+commitflag
																	+ "|工作时间："+worktimes+"小时]</div><table width='100%' bgcolor='#F7FBFF'>"
																	+ "<tr><td align='right' width='18%'>开始时间：</td><td>"
																	+ worklog.starttime
																	+ "</td><td align='right' width='18%'>结束时间：</td><td>"
																	+ worklog.endtime
																	+ "</td>"
																	+ "<td align='right' width='18%'>工作地点：</td><td>"
																	+ worklog.workaddress
																	+ "</td></tr>"
																	+ "<tr><td align='right' width='18%'>工作内容：</td><td colspan='5'><textarea class='showworklog' readonly='readonly'>"
																	+ worklog.workcontent
																	+ "</textarea></td></tr></table>");
										});
					}
				});
	}
</script>
	</head>
	<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
		<div region="west" style="width: 200px; overflow: hidden" id="west">
			<div
				style="background-color: #E0EC00; margin-top: 1px; text-align: center;">
				<a href="javascript:void(0)" onclick="addmydaylog()">添加工作日志</a>
			</div>
			<div id="div1" align="center"></div>
			<div
				style="background-color: #E0EC00; margin-top: 20px; text-align: center;">
				日志查询
			</div>
			<form action="">
				<div>
					<label>
						开始时间:
					</label>
					<input type="text" name="seachstartdate" id="seachstartdate"
						onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" readonly="readonly"/>
				</div>
				<div>
					<label>
						结束时间:
					</label>
					<input type="text" name="seachenddate" id="seachenddate"
						onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" readonly="readonly"/>
				</div>
				<div align="center">
					<a href="javascript:void(0)" class="easyui-linkbutton" plain="true"
						icon="icon-search" onclick="searchworklog()">查询</a>
				</div>
			</form>
		</div>
		<div id="mainPanle" region="center" >
			<div id="showmydaylog">
			欢迎填写工作日志！
			</div>
		</div>
		<div id="addmyworklog" style="display: none; text-align: center;">
			<form action="" id="myworkform" name="myworkform" method="post">
			<input id="id" name="id" type="hidden">
			<input id="iscommit" name="iscommit" type="hidden">
			<input id="userid" name="userid" type="hidden">
				<table align="center" width="100%" >
					<tr>
						<td>
							选择日期：
						</td>
						<td>
							<input type="text" " name="workdate" id="workdate"
								onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" />
						</td>
						<td>
							工作地点：
						</td>
						<td>
							<select name="workaddress" id="workaddress">
								<option value="1">
									1
								</option>
								<option value="2">
									2
								</option>
								<option value="3">
									3
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>
							开始时间：
						</td>
						<td>
							<input type="text" name="starttime" class="Wdate" id="starttime"
								onfocus="WdatePicker({dateFmt:'HH:mm',minDate:'8:00',maxDate:'22:30'})"
								value="9:00" />
						</td>
						<td>
							结束时间：
						</td>
						<td>
							<input type="text" name="endtime" class="Wdate" id="endtime"
								onfocus="WdatePicker({dateFmt:'HH:mm',minDate:'8:00',maxDate:'22:30'})"
								value="17:30" />
						</td>
					</tr>
					<tr>
						<td>
							工作内容：
						</td>
						<td colspan="3">
							<textarea name="workcontent" id="workcontent"
								style="overflow: hidden; width: 350px; height: 350px;" class="easyui-validatebox" required="true"></textarea>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>
